import 'package:common_utils/common_utils.dart';

class TextHelper {
  static String checkText(String? text, {String? defaultText = ''}) {
    if (ObjectUtil.isEmpty(text)) {
      return defaultText!;
    } else {
      return text!;
    }
  }
  static String checkLabel(String? text, {String? defaultText = '- -'}) {
      return checkText(text,defaultText:defaultText);
  }
  ///插入0宽空格 防止长数字、字母整体省略显示
  static String suitEllipsis(String word) {
    if (ObjectUtil.isEmpty(word)||word.isEmpty) {
      return word;
    }
    String breakWord = '';
    for (var element in word.runes) {
      breakWord += String.fromCharCode(element);
      breakWord += '\u200B';
    }
    return breakWord;
  }
}

extension TextFormat on String {
  String get formatLabel => TextHelper.checkText(this, defaultText: '- -');

  String get formatEmpty => TextHelper.checkText(this, defaultText: '');
  String get formatMoney => TextHelper.checkText(this, defaultText: '0.00');
}
